// routes/user.js
const express = require('express');
const authMiddleware = require('../middleware/authMiddleware');

module.exports = (db) => {
    const router = express.Router();

    // GET 获取用户信息（需要认证）
    router.get('/me', authMiddleware, (req, res) => {
        // 假设用户信息已存储在 JWT payload 中
        const userId = req.user.id; 
        db.query('SELECT * FROM users WHERE id = ?', [userId], (err, results) => {
            if (err || results.length === 0) {
                return res.status(404).json({
                    code: 404,
                    success: false,
                    message: 'User not found',
                });
            }
            res.json({
                code: 200,
                success: true,
                data: results[0],
            });
        });
    });

    return router;
};